package com.onlinelearn.paymentservice.actuator;

import com.onlinelearn.paymentservice.repository.PaymentOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class PaymentServiceHealthIndicator implements HealthIndicator {
    @Autowired
    private PaymentOrderRepository orderRepository;

    @Override
    public Health health() {
        try {
            long orderCount = orderRepository.count();
            return Health.up()
                .withDetail("total_orders", orderCount)
                .build();
        } catch (Exception e) {
            return Health.down()
                .withDetail("error", e.getMessage())
                .build();
        }
    }
} 